package com.logic.landseaserver.models.payment.channel;

import java.util.Map;

import org.springframework.stereotype.Service;

import com.logic.landseaserver.common.exception.LandseaException;
import com.logic.landseaserver.common.util.LandSeaUtil;
import com.logic.landseaserver.common.util.StringTools;
import com.logic.landseaserver.domain.BillPayment;
import com.logic.landseaserver.models.payment.PaymentConstant;
import com.logic.landseaserver.models.payment.PaymentConstant.BillPaymentStatus;
import com.logic.landseaserver.models.payment.PaymentConstant.PayBank;
import com.logic.landseaserver.models.payment.bean.PaymentHelperBean;
import com.logic.landseaserver.models.payment.bean.PaymentQueryRequest;
import com.logic.landseaserver.models.payment.bean.PaymentQueryResult;
import com.logic.landseaserver.models.payment.bean.PaymentRequest;

/**
 * 
 *
 * 项目名称：system-server</br>
 * 类名称：PosPaymentChannel</br>
 * 类描述：POS</br>
 * 创建人：Aaron</br>
 * 创建时间：2017年7月17日 下午11:11:19</br>
 * 
 * @version 1.0
 *
 */
@Service(PaymentConstant.GENETRATE_BILLPAYMENT_PREFIX + PaymentConstant.PayChannel.POS)
public class PosPaymentChannel extends AbstractPaymentChannel
{
    //private static final Logger LOGGER = LoggerFactory.getLogger(PosPaymentChannel.class);

    /**
     * 构造payment记录 add by junny
     * @param paymentRequest 支付请求对象
     * @return
     * @throws LandseaException
     */
    @Override
    public BillPayment buildBillPayment(PaymentRequest paymentRequest)
        throws LandseaException
    {
        // 构造BillPayment
        BillPayment insertBillPayment = new BillPayment();
        insertBillPayment.setMoney(LandSeaUtil.get2Double(paymentRequest.getMoney()));
        insertBillPayment.setBank(PayBank.POS);
        
        // 保存图片
        Map<String,Object> extendMap = paymentRequest.getExtendMap();
        
        String imageId = StringTools.getString(extendMap.get("imageId"));
        String transactionNo = StringTools.getString(extendMap.get("transactionNo"));
        insertBillPayment.setImageId(imageId);
        insertBillPayment.setTransactionNo(transactionNo);
        
        return insertBillPayment;
    }
    
    @Override
    public void sendPayRequest(BillPayment billPayment, PaymentHelperBean helperObject, Map<String, Object> resultMap)
        throws LandseaException
    {
        // 没有第三方
        resultMap.put("paymentId", billPayment.getId());
    }
    
    /**
     * 
     * [描述]：处理响应结果/查询支付结果</br>
     *
     * @param billPayment
     * @param paymentResponse
     * @param resultMap
     * @throws LandseaException
     *
     */
    @Override
    public boolean analysisResult(BillPayment billPayment, Object response, PaymentHelperBean helperObject,
        Map<String, Object> resultMap)
        throws LandseaException
    {
        //没有对接第三方，则直接默认成功
        billPayment.setStatus(BillPaymentStatus.SUCCESS);
        return PaymentConstant.RESPONSE_PROCESS_CONTINUE;
    }
    
    @Override
    public void paymentQuery(PaymentQueryRequest paymentQuery, BillPayment billPayment,
        PaymentQueryResult paymentQueryResult, Map<String, Object> resultMap)
        throws LandseaException
    {
    }
    
    @Override
    public void buildResponseResult(BillPayment billPayment, PaymentHelperBean helperObject,
        Map<String, Object> resultMap)
        throws LandseaException
    {
        
    }
    
    @Override
    protected String getProcessClassName()
    {
        return this.getClass().getSimpleName();
    }
}
